package com.elysia.gulimall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.elysia.gulimall.product.entity.ProductAttrValueEntity;
import com.elysia.gulimall.product.service.ProductAttrValueService;
import com.elysia.gulimall.product.vo.AttrRespVo;
import com.elysia.gulimall.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.elysia.gulimall.product.service.AttrService;
import com.elysia.common.utils.PageUtils;
import com.elysia.common.utils.R;



/**
 * 商品属性
 *
 * @author lixinli
 * @email 1994883492@qq.com
 * @date 2024-09-30 01:24:58
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;
    @Autowired
    private ProductAttrValueService productAttrValueService;
    /**
     * 修改商品规格
     * /product/attr/update/{spuId}
     */
    @PostMapping("/update/{spuId}")
    public R updateSpuBaseAttrValue(@RequestBody List<ProductAttrValueEntity> attrValues,@PathVariable Long spuId){
        productAttrValueService.updateSpuBaseAttrValue(attrValues,spuId);
        return R.ok();
    }
    /**
     * 获取spu规格
     * /product/attr/base/listforspu/{spuId}
     * 显示400的，去人人开发平台的菜单管理那里，添加一个 product/attrupdate 的菜单路由
     * gulimall_admin 下面sys_menu，加上这一段  76,37,规格维护,product/attrupdate,,1,log,0
     */
    @GetMapping("/base/listforspu/{spuId}")
    public R baseAttrListForSpu(@PathVariable Long spuId){
        List<ProductAttrValueEntity> list=productAttrValueService.baseAttrListForSpu(spuId);
        return R.ok().put("data",list);
    }

    /**
     * 查询属性，base为基本属性，sale为销售属性
     * @param params
     * @param catelogId
     * @return
     */
    @GetMapping("/{attrType}/list/{catelogId}")
    public R baseList(@RequestParam Map<String, Object> params,@PathVariable("catelogId") Long catelogId,@PathVariable("attrType") String attrType){
        PageUtils page = attrService.queryPage(params,catelogId,attrType);
        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		AttrRespVo attr = attrService.getAttrInfo(attrId);
        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr){
		attrService.save(attr);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
